package com.terrace.core.spring.datasource.interceptor;

import java.io.Serializable;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 数据源拦截器
 * @author jiangyg
 *
 */
public class DataSourceInterceptor extends DataSourceAspectSupport implements MethodInterceptor, Serializable {

	private static final long serialVersionUID = 8345069979453988835L;
	
	@Override
	public Object invoke(final MethodInvocation invocation) throws Throwable {
		
		DataSourceInvoker dataSourceInvoker = new DataSourceInvoker() {
			
			@Override
			public Object invoke() {
				try {
					return invocation.proceed();
				} catch (Throwable ex) {
					throw new DataSourceThrowableWrapper(ex);
				}
			}
			
		};
		
		return execute(dataSourceInvoker, invocation.getThis(), invocation.getMethod(), invocation.getArguments());
	}

}
